#include "part_geom.h"

#include "util/log.h"		    // log
#include "util/common_macros.h"		// macros
#include "util/mmgr.h"		    // Needs to come in early

using namespace part2d;

PartGeom::PartGeom() :
	m_GeomC(0)
{

}

PartGeom::~PartGeom()
{

}

void	PartGeom::AddGeom(const math::Vec2& Pos, float R)
{
	if (m_GeomC < MAX_GEOM)
	{
		m_GeomA[m_GeomC].Pos = Pos;
		m_GeomA[m_GeomC].Radius  = R;
		m_GeomA[m_GeomC].Radius2 = R*R;
		m_GeomC++;
	}
}

void	PartGeom::Collide(Particle2D* particles, int ParticleC)
{
	for (int j=0; j<m_GeomC;j ++)
	{
		Geom* pGeom=&m_GeomA[j];
		for (int i=0; i<ParticleC; i++)
		{
			Particle2D* pPart = &particles[i];
			if (pPart->Active)
			{
				math::Vec2	dist = pGeom->Pos - pPart->Pos;
				float	Mag = dist.MagSqr();
				if (Mag < pGeom->Radius2)
				{
					if (Mag < 0.0001f)
					{
						dist = pPart->Dir;
					} else
					{
						dist.Normalize();
					}
					pPart->Pos = pGeom->Pos - (dist * pGeom->Radius);					
				}
			}
		}
	}
}
